/*
 * Created on Mar 3, 2010
 */
package com.mgmaps.tools;

import com.nutiteq.components.Point;
import com.nutiteq.components.WgsPoint;
import com.nutiteq.maps.projections.Ellipsoid;

public class GeoTools {

  public static final double METERS_PER_MILE = 1609.344;
  public final static double METERS_PER_HOUR_PER_KNOT = 1852.00;
  
  public static final int NAN = -1000000000;

  private GeoTools() {
  }

  public static double metersToMiles(double distanceInMeters) {
    return distanceInMeters/METERS_PER_MILE;
  }

  public static double milesToMeters(double distanceInMiles) {
    return distanceInMiles*METERS_PER_MILE;
  }

  public static double getPixelSizeInMeters(Ellipsoid ell, WgsPoint p, int zoom, int tileSize) {
    final double latrad = Math.toRadians(p.getLat());
    final double pixsize = (2 * ell.getEquatorialRadius() * Math.PI) // equator length
      * Math.cos(latrad) / (1<<(zoom)) / tileSize;
    return pixsize;
  }
  
  public static Point toPoint(WgsPoint p) {
    return new Point((int) (p.getLon() * 1000000), (int) (p.getLat() * 1000000));
  }
  
  public static WgsPoint fromPoint(Point p) {
    return new WgsPoint(p.getX() / 1000000.0, p.getY() / 1000000.0);
  }
}
